#!/usr/bin/python

D = {'food' : 'Spam', 'quantity' : 4, 'color' : 'pink'}
print D
print D['food']
try:
	print D['lala']
except Exception, e:
	print repr(e)
print D
D['quantity'] += 1
print D

d = {}
d['name'] = 'Bob'
d['job'] = 'dev'
d['age'] = 40
print d
print(d['name'])

rec = 	{'name' : {'first':'Bob', 'last':'Smith'},
		 'job' : ['dev', 'mgr'],
		 'age' : 40.5}
print rec
print rec['name']
print rec['job']
print rec['age']
print rec['name']['first'] + " " + rec['name']['last']
print rec['job'][-1]
rec['job'].append('janitor')
print rec


# NOTE: In Python 3 method dict.keys() returns object, and you should use list(dict.keys())
ks = rec.keys()
print ks
ks3 = list(rec.keys())
print ks3
ks.sort()
print ks
for key in ks:
	print(key, '=>', rec[key])

for key in sorted(rec):
	print(key, '=>', rec[key])

thedict = {}
print thedict
for c in "spam":
	thedict[c.upper()] = None
	print(c.upper())
print thedict	
x = 4
while x > 0:
	thedict["SPAM"[-x]] = 'spam!'*x
	print('spam!'*x)
	x -= 1
print thedict
